$(document).ready(function() {
	ko.applyBindings(new productsViewModel(), $("#products-container")[0]);
	ko.applyBindings(new marketsViewModel(), $("#markets-container")[0]);
});

function productsViewModel() {
	var self = this;
	
	self.products = ko.observableArray();
	
	self.getProductsSuccess = function(products) {
		self.products($.map(products.elements, function (product) { return new Product(product); }));
	};
	
	self.showProducts = function(products) {
		$(products).show();
	};
	
	self.pager = ko.observable(new Pager({ webService: "product/getProductsPageByKeyword", params : { "pageNumber" : 1, "pageSize" : 8, "keyword": keyword }, onSuccess: self.getProductsSuccess }));
};

function marketsViewModel() {
	var self = this;
	
	self.markets = ko.observableArray();
	
	self.getMarketsSuccess = function(markets) {
		self.markets($.map(markets.elements, function (market) { return new Market(market); }));
	};
	
	self.showMarkets = function(markets) {
		$(markets).show();
	};
	
	self.pager = ko.observable(new Pager({ webService: "markets/getMarketsPageByKeyword", params : { "pageNumber" : 1, "pageSize" : 8, "keyword": keyword }, onSuccess: self.getMarketsSuccess }));
};